#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>

int GetDirnums(char* path){
    int nums=0;
    DIR *p=opendir(path);
    struct dirent *pdir=readdir(p);
    while(1){
        if(pdir==NULL){
            return nums;
        }
        if(pdir->d_type==DT_DIR && strcmp(pdir->d_name,".")!=0
           &&strcmp(pdir->d_name,".")!=0){
            nums++;
            char buf[300]={0};
            sprintf(buf,"%s/%s",path,pdir->d_name);
            int sonsum= GetDirnums(buf);
            nums +=sonsum;
        }

    }
    return 0;
}

int main(){
    int sum=GetDirnums("./test");
    printf("Dirnums: %d\n",sum);
    return 0;
}


